package com.dyz.leetcode._10_slidingWindow;

public class _485_findMaxConsecutiveOnes {
    //直接模拟
    public int findMaxConsecutiveOnes(int[] nums) {
        int ones = 0;
        int ans = 0;
        for(int num:nums){
            if(num==1){
                ones++;
            }else {
                ans = Math.max(ans, ones);
                ones=0;
            }

        }
        return Math.max(ans, ones);
    }
    //滑动窗口
    public int findMaxConsecutiveOnes1(int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = 0;
        int ans = 0;
        int windowOne = 0;
        while(right<n){
            if (nums[right]==0) {
                ans = Math.max(ans, right-left);
                left = right+1;
            }
            right++;
        }
        return Math.max(ans, right-left);
    }


}
